package com.itheima.consumer.controller;

import com.itheima.consumer.domain.Goods;
import com.itheima.consumer.service.GoodsService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("provider")
public class GoodController {
    @Autowired
    private GoodsService goodsService;
    @GetMapping("/goods/{id}")
    @HystrixCommand(fallbackMethod = "findOne_fallback",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "4000")
    })
    public Goods findOne(@PathVariable("id") String id) throws InterruptedException {
        if("1".equals(id)){
            int i = 3 / 0;
        }
        return goodsService.findOne(id);
    }

    public Goods findOne_fallback(String id){
        Goods goods = new Goods();
        goods.setName("降级了");
        return goods;
    }

}
